set -e

if [ -n "${1}" ]; then
  TARGET_DATE="${1}"
else
  TARGET_DATE="$(TZ="GMT" date --date='1 days ago' '+%Y%m%d')"
fi

echo "Target Date: $TARGET_DATE"
REPO_ROOT="/remote/iosg/home-8/bot-hft/jenkins/workspace/coin2_feed_stats/coin/"
cd "${REPO_ROOT}"
#git pull || true
#git submodule update --recursive

START_DATE="${TARGET_DATE}"
END_DATE="$(date --date=@$(( $(date +%s --date=${START_DATE}) + 86400 )) '+%Y%m%d')"

echo "START_DATE=${START_DATE}"
echo "END_DATE=${END_DATE}"

source /remote/iosg/home/bot-hft/miniconda3/etc/profile.d/conda.sh

# build py_symbology.so
# conda activate /remote/iosg/home/bot-hft/miniconda3/envs/coin2_motion_env
export TZ=UTC
export HOME=/remote/iosg/home-8/bot-hft
# bazel build -c opt --strip=always //cc/appcoin2/support/symbology:py_symbology.so
# conda deactivate

conda activate /remote/iosg/home/bot-hft/miniconda3/envs/coin2_motion_env_migration
cd python

./pyrunner coin/support/feed_tool/feed_stats/app/coin2_feed_stats_checker.py \
  --start_date=${START_DATE} \
  --end_date=${END_DATE} \
  --slack_send=True
